#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc,char const* argv[])
{
    int fd_dest=-1;
    int fd_fifo=-1;
    int count=0;
    char buf[32]="";

    fd_dest=open(argv[1],O_WRONLY|O_CREAT|O_TRUNC,0666);
    if(fd_dest<0)
    {
        perror("src open err\n");
        return -1;
    }

    fd_fifo=open("./fifo",O_RDONLY);
    if(fd_fifo<0)
    {
        perror("fifo open err\n");
        close(fd_dest);
        return -1;
    }

    while((count=read(fd_fifo,buf,32))>0)
    {
        write(fd_dest,buf,count);
    }

    printf("output end!\n");

    close(fd_dest);
    close(fd_fifo);

    return 0;
}